<?php

namespace Blog\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\ExecutionContext;

/**
 * Blog\BlogBundle\Entity\NewsArticles
 */
class NewsArticles
{
    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $title
     */
    private $title;

    /**
     * @var string $image
     */
    private $image;

    /**
     * @var text $content
     */
    private $content;

    /**
     * @var datetime $createdAt
     */
    private $createdAt;

    /**
     * @var integer $authorId
     */
    private $authorId;

    /**
     * @var boolean $active
     */
    private $active;

    /**
     * @var Blog\BlogBundle\Entity\NewsCategories
     */
    private $category;

    /**
     * @var Blog\BlogBundle\Entity\NewsSection
     */
    private $section;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set image
     *
     * @param string $image
     */
    public function setImage($image)
    {
        $this->image = $image;
    }

    /**
     * Get image
     *
     * @return string 
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Set content
     *
     * @param text $content
     */
    public function setContent($content)
    {
        $this->content = $content;
    }

    /**
     * Get content
     *
     * @return text 
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * Set createdAt
     *
     * @param datetime $createdAt
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;
    }

    /**
     * Get createdAt
     *
     * @return datetime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set authorId
     *
     * @param integer $authorId
     */
    public function setAuthorId($authorId)
    {
        $this->authorId = $authorId;
    }

    /**
     * Get authorId
     *
     * @return integer 
     */
    public function getAuthorId()
    {
        return $this->authorId;
    }

    /**
     * Set active
     *
     * @param boolean $active
     */
    public function setActive($active)
    {
        $this->active = $active;
    }

    /**
     * Get active
     *
     * @return boolean 
     */
    public function getActive()
    {
        return $this->active;
    }

    /**
     * Set category
     *
     * @param Blog\BlogBundle\Entity\NewsCategories $category
     */
    public function setCategory(\Blog\BlogBundle\Entity\NewsCategories $category)
    {
        $this->category = $category;
    }

    /**
     * Get category
     *
     * @return Blog\BlogBundle\Entity\NewsCategories 
     */
    public function getCategory()
    {
        return $this->category;
    }

    /**
     * Set section
     *
     * @param Blog\BlogBundle\Entity\NewsSection $section
     */
    public function setSection(\Blog\BlogBundle\Entity\NewsSection $section)
    {
        $this->section = $section;
    }

    /**
     * Get section
     *
     * @return Blog\BlogBundle\Entity\NewsSection 
     */
    public function getSection()
    {
        return $this->section;
    }
    
    protected $tags;
    public function setTags(ArrayCollection $tags) {
        $this->tags = $tags;
    }
    public function getTags() {
        return $this->tags;
    }
    
    public function __construct() {
        $this->tags = new ArrayCollection();
    }
    public function uploadImage($path)
    {
        if($this->image == null)
            return;
        $fileName = $this->image->getClientOriginalName();
        $this->image->move($path, $fileName);
        $this->setImage($fileName);
    }
    public function isTitleValid(ExecutionContext $ex) {
        // check if the name is actually a fake name
        /*if (!preg_match('/^[a-zA-Za0-9]+$/', $this->getTitle(), $matches)) {
            $propertyPath = $ex->getPropertyPath() . '.title';
            $ex->setPropertyPath($propertyPath);
            $ex->addViolation('Title only contains alpha and number!', array(), $this->getTitle());
            return false;
        }*/
        return true;
    }
}